#ifndef COMMON_LOGGING_H_
#define COMMON_LOGGING_H_

#include <fermat/log/fmtlog.h>
#include <fermat/common/singleton.h>

namespace fermat {

class FmtInnerLogger : public Singleton<FmtInnerLogger>{
public:
    FmtInnerLogger()
    {
        _logger =  fermat::log::stdout_logger_mt("fermat-default", true);
    }
    void setLogger(const fermat::log::LoggerPtr& logger)
    {
        _logger =  logger;
    }

    fermat::log::LoggerPtr getLogger()
    {
        return _logger;
    }

private:
    fermat::log::LoggerPtr _logger;
};

inline fermat::log::LoggerPtr getFmtLogger()
{
    FmtInnerLogger *fmtinner = FmtInnerLogger::getInstance();
    return fmtinner->getLogger();
}

inline void setFmtLogger(const fermat::log::LoggerPtr& logger)
{
    FmtInnerLogger *fmtinner = FmtInnerLogger::getInstance();
    fmtinner->setLogger(logger);
}

}

#define LOG_STR_H(x) #x
#define LOG_STR_HELPER(x) LOG_STR_H(x)
#define LOG_TRACE(...) fermat::getFmtLogger()->trace("[" __FILE__ " line #" LOG_STR_HELPER(__LINE__) "] " __VA_ARGS__)
#define LOG_DEBUG(...) fermat::getFmtLogger()->debug(__VA_ARGS__)
#define LOG_INFO(...) fermat::getFmtLogger()->info(__VA_ARGS__)
#define LOG_WARN(...) fermat::getFmtLogger()->warn(__VA_ARGS__)
#define LOG_ERROR(...) fermat::getFmtLogger()->error(__VA_ARGS__)

#define LOG_SET_LEVEL(l)  fermat::getFmtLogger()->set_level((l))

#endif